package com.tms.crud;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

import com.tms.warehouse.entity.Identificable;

public class PropertyScanner {

	public static List<Attribute> scan(
			Class<? extends Identificable> entityClass) {

		List<Attribute> properties = new LinkedList<Attribute>();
		for (Field field : entityClass.getDeclaredFields()) {
			if (field.isAnnotationPresent(Property.class)) {
				properties.add(new Attribute(field, entityClass));
			}
		}
		return properties;
	}

	public static <T extends Identificable> T newInstance(Class<T> type) {

		try {
			return type.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
